package cn.tradewin.pmp.encoders;

import org.apache.tapestry5.ValueEncoder;
import org.slf4j.Logger;

import cn.tradewin.pmp.persist.model.MDept;
import cn.tradewin.pmp.services.DeptManageService;

public class DeptEncoder implements ValueEncoder<MDept> {

	private final DeptManageService service;
	
	private final Logger log;
	
	public DeptEncoder(DeptManageService service, Logger log) {
		this.service = service;
		this.log = log;
	}
	
	@Override
	public String toClient(MDept value) {
		log.debug("******************step into toClient****************************" + value.getDeptNo());
		return String.valueOf(value.getDeptNo());
	}

	@Override
	public MDept toValue(String clientValue) {
		log.debug("******************step into toValue****************************" + clientValue);
		return service.findDeptByPrimary(Integer.parseInt(clientValue));
	}
}
